package cn.com.oceansoft.osc.ms.schedule.service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by caobo on 2017/7/7.
 */

public  class CallPoliceComno {
    public static final String ptno = "99";  //原本是999区划编号
    //private static Log log = LogFactory.getLog(CallPoliceComno.class);
    public static String comNO;
    public static String date = "";
    public static CallPoliceComno callPoliceComno = null;
    public static int transaction = 9000; //原本是001~999区划编号
    public static synchronized CallPoliceComno getInstance(String deptNo) {
        //初始化基本值
        init(deptNo);
        if (callPoliceComno == null) {
            return new CallPoliceComno();
        }
        return callPoliceComno;
    }
    public static void init(String deptNo) {
        String no = null;
        SimpleDateFormat s = new SimpleDateFormat("YYYYMMdd");
        String da = s.format(new Date());
        if ("".equals(date)) {
            date = da;
        }
        if (!da.equals(date) || transaction == 9999) {
            transaction = 9000;
        }
        try {
            no = deptNo.substring(0, 6); //区划编号
        } catch (NullPointerException e) {
            //log.error("deptNo不为空");
            throw new NullPointerException();
        } catch (IndexOutOfBoundsException e) {
            //log.error("deptNo下标越界");
            throw new IndexOutOfBoundsException();
        }
        SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMddHHmmss");
        String date = sdf.format(new Date());//日期(8位)+时间(6位)
        transaction++;
        comNO = no + date + ptno + String.valueOf(transaction);
    }
    //    public static void main(String arg[]) {
//        for (int i = 0; i < 10000; i++) {
//            CallPoliceComno comno = CallPoliceComno.getInstance("222400000000");
//            String n = comno.getComNO();
//            if (i < 9990 && i > 10) {
//                continue;
//            }
//            System.out.println(n);
//        }
//        System.out.println();
//    }
    public static String getComNO() {
        return comNO;
    }
}

